﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ActionListItem : MonoBehaviour,INormalItem {

    public Image image;
    public UGUIToggle toggle;
    public Text actionName;

    private bool select = false;
    private Data.Action action;

    private ActionClipInfo actionClipInfo;
    public void SetData(Data.Action action,AnimClipInfo animInfo)
    {
        if (animInfo == null)
        {
            image.color = new Color(219f / 255, 134f / 255, 134f / 255, 227f / 255);
        }
        else
        {
            image.color = new Color(1, 1, 1,27f / 255);
        }
        actionClipInfo = new ActionClipInfo(animInfo, action);
        this.action = action;
        actionName.text = action.Name;
        toggle.onValueChangedEvent = ActionToggle;
    }

    private void ActionToggle(object obj,bool toggle)
    {
        select = toggle;
        if (toggle == true)
        {
            EventManager.TriggerEvent<Data.Action,ActionListItem>(CommonEvent.SelectOneActionDataToSubPanel, action,this);
            EventManager.TriggerEvent<ActionClipInfo>(CommonEvent.SelectOneActionDataToCameraCtr0, actionClipInfo);
        }
    }

    public void DelateThisAction()
    {
        EventManager.TriggerEvent<Data.Action, ActionListItem>(CommonEvent.DelatetOneActionData, action,this);
    }

    public void OnRecycle()
    {
        toggle.isOn = false;
        toggle.onValueChangedEvent = null ;
    }
}
